package com.hdu.dwh.dtos.cdc_dtos;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hdu.dwh.utils.CDCUtils;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class MysqlcdcDtos extends FlinkJobDto {

    public MysqlcdcDtos(){}

    public MysqlcdcDtos(String address, Integer port, String username, String password, String sourceDatabaseName, String sourceTableName, String targetDatabaseName, String targetTableName) {
        this.address = address;
        this.port = port;
        this.username = username;
        this.password = password;
        this.sourceDatabase = sourceDatabaseName;
        this.sourceTable = sourceTableName;
        this.targetDatabase = targetDatabaseName;
        this.targetTable = targetTableName;
    }

    @Schema(hidden = true)
    private String entryClass = "org.apache.paimon.flink.action.FlinkActions";
    
    @Schema(description = "mysql地址", defaultValue = "127.0.0.1:3306")
    private String address;

    @Schema(description = "mysql端口", defaultValue = "3306")
    private Integer port;

    @Schema(description = "mysql用户名", defaultValue = "root")
    private String username;

    @Schema(description = "mysql密码", defaultValue = "datawarehouse")
    private String password;

    @Schema(description = "mysql数据库名", defaultValue = "ssb-test")
    private String sourceDatabase;

    @Schema(description = "mysql表名", defaultValue = "dates")
    private String sourceTable;

    @Schema(description = "paimon数据库名", defaultValue = "ssb")
    private String targetDatabase;

    @Schema(description = "paimon表名", defaultValue = "dates")
    private String targetTable;

    @Schema(hidden = true)
    public List<String> getMysqlCDCConfigList() {
        if (this.address == null || this.port == null || this.username == null || this.password == null || this.sourceDatabase == null || this.sourceTable == null) {
            throw new IllegalArgumentException("参数不能为空" + this.toString());
        }
        // "mysql_sync_table", "--warehouse", "file:///opt/paimon/warehouse", "--database", "ssb-test", "--table", "dates", "--mysql_conf", "hostname=127.0.0.1", "--mysql_conf", "port=3306", "--mysql_conf", "username=root", "--mysql_conf", "password=datawarehouse", "--mysql_conf", "database-name=ssb-test", "--mysql_conf", "table-name=dates"
        // List<String> config = List.of(
        //     "mysql_sync_table",
        //     "--warehouse", "s3://paimon/warehouse",
        //     "--database", this.targetDatabase,
        //     "--table", this.targetTable,
        //     "--mysql_conf", "hostname=" + this.address,
        //     "--mysql_conf", "port=" + this.port,
        //     "--mysql_conf", "username=" + this.username,
        //     "--mysql_conf", "password=" + this.password,
        //     "--mysql_conf", "database-name=" + this.sourceDatabase,
        //     "--mysql_conf", "table-name=" + this.sourceTable
        // );
        List<String> config = CDCUtils.buildMysqlCDCParamList(address, port, username, password, targetDatabase, sourceDatabase, targetTable, sourceTable);
        return config;
    }




}
